package cn.ichiva.web.component;

import cn.ichiva.web.common.Bus;
import cn.ichiva.web.common.Topic;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;

import java.io.IOException;

class TabBarLabel extends HBox {
        String labelTitle;
        String labelUrl;

        public TabBarLabel(String title, String url){
            this.labelTitle = title;
            this.labelUrl = url;

            FXMLLoader fxmlLoader = new FXMLLoader(TabBarLabel.class.getResource("/TabBarLabel.fxml"));
            fxmlLoader.setRoot(this);
            fxmlLoader.setController(this);

            try {
                fxmlLoader.load();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            this.title.setText(title);
            setOnMouseClicked(event -> Bus.publish(Topic.ActionLabel,labelUrl));
        }

        @FXML
        Label title;

        @FXML
        public void close(){
            Bus.publish(Topic.CloseLabel,labelUrl);
        }
    }